package com.zengdada.authority.mapper;

import com.zengdada.authority.model.AppUser;
import com.zengdada.authority.utils.mapper.Sort;
import com.zengdada.authority.utils.where.result.MapperAnalysisResultMerge;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface AppUserMapper extends Mapper<AppUser> {

    @Select("<script> SELECT DISTINCT *  from syoauth.app_user u where u.id <if test=\"isIn != true\"> NOT </if> " +
            "        IN(SELECT DISTINCT urr.app_user_id  from syoauth.app_user_role_rel urr  where state = 1 and app_role_id = #{roleId,jdbcType=VARCHAR} ) " +
            "     <if test=\"null != where and where.isNull != true\"> and ${where.extraFilter}</if> " +
            "     <if test=\"sort!=null\"> ORDER BY ${sort.orderDetailed} </if> </script> ")
    List<Map<String, Object>> selectUsersByRoleId(@Param("isIn") boolean isIn, @Param("roleId") String roleId, @Param("where") MapperAnalysisResultMerge where, @Param("sort") Sort sort);
}